﻿/*
 *  Author: Louis A. Leskoviansky
 *  Company: Artemis Solutions Group (http://www.artemis-solutions.com)
 */


using System;
using System.Collections.Generic;

namespace AjaxControlFramework
{
    /// <summary>
    /// Encapsulates the state and HTML content of a server control to enable with AJAX capabilities.
    /// </summary>
    public class AjaxControlContext
    {
        //------// Properties \\--------------------------------------------\\
        /// <summary>
        /// Gets and sets the custom state collection of an AjaxControl.
        /// </summary>
		private Dictionary<string, object> _state = new Dictionary<string, object>();
        public Dictionary<string, object> State
        {
			get { return _state; }
			set { _state = value; }
        }


        private Dictionary<string, object> _properties = new Dictionary<string, object>();
        public Dictionary<string, object> Properties
        {
            get { return _properties; }
            set { _properties = value; }
        }


        /// <summary>
        /// Gets and sets the HTML content of the server control the AjaxControl encapsulates.
        /// </summary>
        private string _html = String.Empty;
        public string Html
        {
			get { return _html; }
			set { _html = value; }
        }


        /// <summary>
        /// Gets and sets a reference to the server control the AjaxControl encapsulates.
        /// </summary>
		public System.Web.UI.Control Control { get; set; }


		/// <summary>
		/// Gets the UniqueID property value of the server control the AjaxControl encapsulates.
		/// </summary>
		public virtual string ID
		{
			get { return Control.UniqueID; }
		}


        public virtual RedirectOptions RedirectOptions { get; set; }


        public virtual CallbackStrategyArguments CallbackArguments { get; set; }


        private List<System.Web.UI.WebControls.BaseValidator> _validators = null;
        public virtual List<System.Web.UI.WebControls.BaseValidator> Validators
        {
            get
            {
                if (_validators == null)
                {
                    _validators = AjaxControlUtils.FindChildControlsByType<System.Web.UI.WebControls.BaseValidator>(Control);
                }

                return _validators;
            }
        }


        public virtual bool ValidationScriptShouldBeLoaded
        {
            get
            {
                return (CallbackArguments.CallbackMethod == "Load" && !CallbackArguments.ValidationScriptLoaded && Validators.Count > 0);
            }
        }
        //------\\ Properties //--------------------------------------------//
    }
}
